/* make new directory */
local dir `c(pwd)'
capture mkdir length_validation_VI


local dir `c(pwd)'
use entropy_bible, clear
merge m:1 trans using data_bible_final, keep(3)
gen tokeep=0
forvalues b=40/66 {
	replace tokeep=1 if book==`b'
}
keep if tokeep==1
drop tokeep
bysort trans: gen books=_N
*Only translations with all available 27 books are beeing kept
keep if books==27
drop books

bysort trans: gen id=_n
keep if id==1
keep trans language latitude longitude family ISO
gen random=runiform()

	egen group = cut(random), group(`1') label
	
sum group
local min=r(min)
local max=r(max)

forvalues g=`min'/`max' {
	preserve
	keep if group==`g'
	save "`dir'\bible_index_`g'", replace
	/************ insert the working directory of Stata here ************/
	winexec C:\Program Files (x86)\Stata14\StataMP-64 -q do `dir'\length_validation_VI.do `g'
	restore
}

clear         
/* wait until everything is finished */
clear
 forvalues g=`min'/`max' {  
   capture confirm file finished_`g'.dta
   while _rc != 0 {
      sleep 2000
      capture confirm file finished_`g'.dta
   }
 }

forvalues g=`min'/`max' {
	capture erase finished_`g'.dta
}

exit
